import req from '@/utils/request'
import type {
  GetProductSPUParams,
  ProductSPUData,
  SaleAttrList,
  BaseTrandemarkList,
  SPUParamsType2,
  SpuImageListType,
  SpuSaleAttrListType,
  FindBySpuIdDataList,
  AttrInfoList,
  SaveSkuInfoParams,
} from './model/SPUType'

enum Api {
  product = '/admin/product',
  baseSaleAttrList = '/admin/product/baseSaleAttrList',
  baseTrandemarkList = '/admin/product/baseTrademark/getTrademarkList',
  saveSpuInfo = '/admin/product/saveSpuInfo',
  spuImageList = '/admin/product/spuImageList',
  spuSaleAttrList = '/admin/product/spuSaleAttrList',
  updateSkuInfo = '/admin/product/updateSpuInfo',
  deleteSpu = '/admin/product/deleteSpu',
  findBySpuId = '/admin/product/findBySpuId',
  attrInfoList = '/admin/product/attrInfoList',
  saveSkuInfo = '/admin/product/saveSkuInfo',
  getSpuById = '/admin/product/getSpuById',
}

// 获取分类下的SPU信息
export const getProductSPU = ({
  page,
  limit,
  category3Id,
}: GetProductSPUParams) => {
  return req.get<null, ProductSPUData>(
    `${Api.product}/${page}/${limit}?category3Id=${category3Id}`
  )
}

// 获取基本销售信息
export const getBaseSaleAttrList = () => {
  return req.get<null, SaleAttrList>(Api.baseSaleAttrList)
}

// 获取基本品牌信息
export const getTrandemarkList = () => {
  return req.get<null, BaseTrandemarkList>(Api.baseTrandemarkList)
}

// 添加spu属性
export const addSpuInfo = (data: SPUParamsType2) => {
  return req.post(Api.saveSpuInfo, data)
}

// 获取spu图片列表
export const getSpuImageList = (spuId: number) => {
  return req.get<null, SpuImageListType[]>(Api.spuImageList + '/' + spuId)
}
// 获取销售属性值列表
export const getSpuSaleAttrList = (spuId: number) => {
  return req.get<null, SpuSaleAttrListType[]>(Api.spuSaleAttrList + '/' + spuId)
}
// 修改销售属性
export const updateSkuInfoApi = (data: SPUParamsType2) => {
  return req.post<null, null>(Api.updateSkuInfo, data)
}
// 删除SPU属性
export const deleteSpuApi = (id: number) => {
  return req.delete<null, null>(`${Api.deleteSpu}/${id}`)
}

// 根据spuid 查看sku列表
export const findBySpuIdApi = (id: number) => {
  return req.get<null, FindBySpuIdDataList>(`${Api.findBySpuId}/${id}`)
}

// 获取商品基础属性接口
export const getAttrInfoListApi = (
  category1Id: number,
  category2Id: number,
  category3Id: number
) => {
  return req.get<null, AttrInfoList>(
    `${Api.attrInfoList}/${category1Id}/${category2Id}/${category3Id}`
  )
}

// 添加sku属性
export const saveSkuInfoApi = (data: SaveSkuInfoParams) => {
  return req.post<null, null>(Api.saveSkuInfo, data)
}

// 根据spuId获取spu信息
export const getSpuByIdApi = (id: number) => {
  return req.get<null, SPUParamsType2>(`${Api.getSpuById}/${id}`)
}
